home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Include / FWTxtShp.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  7.3 KB  |  239 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTextS.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWTXTSHP_H
  13. #define FWTXTSHP_H
  14.  
  15. #ifndef FWSHAPE_H
  16. #include "FWShape.h"
  17. #endif
  18.  
  19. #ifndef FWDFAULT_H
  20. #include "FWDfault.h"
  21. #endif
  22.  
  23. // ----- Macintosh Includes -----
  24.  
  25. #if defined(FW_BUILD_MAC) && !defined(__TEXTEDIT__)
  26. #include <TextEdit.h>
  27. #endif
  28.  
  29. //==============================================================================
  30. //    •• Forward Declarations
  31. //==============================================================================
  32.  
  33. class FW_CGraphicContext;
  34. class FW_CTextShapeRep;
  35. class FW_CRectShape;
  36. class FW_COvalShape;
  37. class FW_CRoundRectShape;
  38. class FW_CArcShape;
  39. class FW_CLineShape;
  40. class FW_CRegionShape;
  41.  
  42. //========================================================================================
  43. //    •• Defines
  44. //========================================================================================
  45.  
  46. enum FW_TextAlignment {
  47.     FW_kAscentLine,
  48.     FW_kBaseLine,
  49.     FW_kDescentLine
  50. };
  51.  
  52. //========================================================================================
  53. //    •• CLASS FW_CTextShape
  54. //========================================================================================
  55.  
  56. class FW_CTextShape : public FW_CShape
  57. {
  58. //----------------------------------------------------------------------------------------
  59. //    • Constructors
  60. //
  61. public:
  62.     FW_CTextShape();
  63.     FW_CTextShape(long byteCount,  const char* text, 
  64.                     const FW_CPoint& position = FW_kZeroPoint,
  65.                      FW_TextAlignment textAlignment = FW_kBaseLine);
  66.     FW_CTextShape(const FW_CString& string, 
  67.                     const FW_CPoint& position = FW_kZeroPoint,
  68.                       FW_TextAlignment textAlignment = FW_kBaseLine);
  69.     
  70.     FW_CTextShape(const FW_CTextShape& other);
  71.     FW_CTextShape(FW_CTextShapeRep* rep);
  72.             
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    • Operators
  76. //
  77. public:
  78.     FW_CTextShape& operator=(const FW_CTextShape& other);
  79.     FW_CTextShape& operator=(FW_CTextShapeRep* other);
  80.         
  81.     FW_CTextShapeRep* operator->() const
  82.                 {return (FW_CTextShapeRep*)GetRep();}
  83.     
  84. //----------------------------------------------------------------------------------------
  85. //    • Conversion
  86. //
  87. public:
  88.     operator FW_CRectShape() const;
  89.     operator FW_COvalShape() const;
  90.     operator FW_CRoundRectShape() const;
  91.     operator FW_CArcShape() const;
  92.     operator FW_CLineShape() const;
  93.     operator FW_CRegionShape() const;
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    • Static Methods
  97. //
  98. public:
  99.     static void DrawText(FW_CGraphicContext* graphicContext, 
  100.                           long byteCount,
  101.                           const char* text,
  102.                           const FW_CPoint& position,
  103.                               FW_TextAlignment textAlignment = FW_kBaseLine);
  104.     static void DrawString(FW_CGraphicContext* graphicContext, 
  105.                               const FW_CString& string,
  106.                               const FW_CPoint& position,
  107.                               FW_TextAlignment textAlignment = FW_kBaseLine);
  108. };
  109.  
  110. //==============================================================================
  111. //    •• class FW_CTextShapeRep
  112. //==============================================================================
  113.  
  114. class FW_CTextShapeRep : public FW_CShapeRep
  115. {
  116.     friend class FW_CTextShape;
  117.     
  118. //------------------------------------------------------------------------------
  119. //    • Constructors/Destructors
  120. //
  121. protected:
  122.     FW_CTextShapeRep();    
  123.     FW_CTextShapeRep(long byteCount, const char* text, 
  124.                     const FW_CPoint& position,
  125.                       FW_TextAlignment textAlignment);
  126.     FW_CTextShapeRep(const FW_CString& string, 
  127.                     const FW_CPoint& position,
  128.                       FW_TextAlignment textAlignment);
  129.     
  130.     virtual ~FW_CTextShapeRep();
  131.     
  132. //------------------------------------------------------------------------------
  133. //    • Inherited API
  134. //
  135. public:
  136.     // ----- Hit Testing -----
  137.     virtual FW_HitTestPart HitTest(const FW_CPoint& test) const;
  138.  
  139.     // ----- Rendering -----
  140.     virtual void     Draw(FW_CGraphicContext* graphicContext);
  141.     virtual void     Draw(FW_CGraphicContext* graphicContext, 
  142.                         const FW_CRect& box,
  143.                         FW_Justification justification = FW_kFlushDefault);
  144.     
  145.     static void    DrawText(FW_CGraphicContext* graphicContext,
  146.                              long byteCount, 
  147.                              const char* text,
  148.                              const FW_CPoint& position,
  149.                              FW_TextAlignment textAlignment);
  150.     static void    DrawString(FW_CGraphicContext * graphicContext,
  151.                                  const FW_CString& string,
  152.                                  const FW_CPoint& position,
  153.                                 FW_TextAlignment textAlignment);
  154.     
  155.     // ----- Transform -----
  156.     virtual void    Transform(XMPTransform* transform);
  157.     virtual void    InverseTransform(XMPTransform* transform);
  158.  
  159.     virtual void    MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY);
  160.     virtual void    MoveShapeTo(XMPCoordinate x, XMPCoordinate y);
  161.  
  162.     // ----- Geometry -----
  163.     virtual FW_CRect GetShapeBounds() const;
  164.  
  165.     // ----- Default shape -----
  166.     virtual void     SetAsDefault() const;
  167.  
  168.     // ----- Stream -----
  169.     virtual void    Flatten(FW_CWritableStream& stream);
  170.     virtual void    Unflatten(FW_CReadableStream& stream);
  171.  
  172. //------------------------------------------------------------------------------
  173. //    • New API
  174. //
  175. public:
  176.     FW_CTextShape        Copy() const;
  177.  
  178.     long                GetByteCount() const
  179.                             {return fByteCount;}
  180.     
  181.     FW_CPoint            GetPosition() const
  182.                             {return fPosition;}
  183.     FW_TextAlignment    GetTextAlignment() const
  184.                             {return fTextAlignment;}
  185.     long                GetText(char* text) const;
  186.  
  187.     void                SetPosition(const FW_CPoint& position)
  188.                             {fPosition = position; Changed();}
  189.     void                SetText(long byteCount, const char* text);
  190.     void                SetTextAlignment(FW_TextAlignment textAlignment)
  191.                             {fTextAlignment = textAlignment; Changed();}
  192.  
  193. #ifdef FW_BUILD_MAC
  194.     void                GetMacTextStyle(TextStyle& theTextStyle) const;
  195. #endif
  196.  
  197. private:
  198.     static FW_SPlatformPoint CalcTextPosition(FW_CGraphicContext* graphicContext,
  199.                                                 const FW_CPoint& position,
  200.                                                 FW_TextAlignment textAlignment);
  201.                                                 
  202. //------------------------------------------------------------------------------
  203. //    • Data Members
  204. //
  205. protected:
  206.     long                     fByteCount;
  207.     char*                     fText;
  208.     FW_CPoint                fPosition;
  209.     FW_TextAlignment        fTextAlignment;
  210. };
  211.  
  212. //==============================================================================
  213. //    •• Inlines
  214. //==============================================================================
  215.  
  216. //------------------------------------------------------------------------------
  217. //    • FW_CTextShape::DrawText
  218. //------------------------------------------------------------------------------
  219. inline static void FW_CTextShape::DrawText(FW_CGraphicContext* graphicContext, 
  220.                                               long byteCount,
  221.                                               const char* text,
  222.                                               const FW_CPoint& position,
  223.                                             FW_TextAlignment textAlignment)
  224. {
  225.     FW_CTextShapeRep::DrawText(graphicContext, byteCount, text, position, textAlignment);
  226. }
  227.  
  228. //------------------------------------------------------------------------------
  229. //    • FW_CTextShape::DrawString
  230. //------------------------------------------------------------------------------
  231. inline static void FW_CTextShape::DrawString(FW_CGraphicContext* graphicContext, 
  232.                                               const FW_CString& string,
  233.                                               const FW_CPoint& position,
  234.                                             FW_TextAlignment textAlignment)
  235. {
  236.     FW_CTextShapeRep::DrawString(graphicContext, string, position, textAlignment);
  237. }
  238.  
  239. #endif